<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends Controller {
    public function index(){
        if(session('?user.uid')){
            $this->display();
        }else{
            $this->display('login');
        }
    }
    public function login(){
        session(null);
        $this->display();
    }
    public function dologin(){
        $data=null;
        $name=I('name');
        $password=I('password');
        $row=M('admin_user')->where(array('username'=>$name))->select();
        if(!empty($row)){
            if($row[0]['password']==$password){
                $data['code']='0000';
                $data['message']='验证通过';
                session('user.uid',$row[0]['id']);
                session('user.pickname',$row[0]['pickname']);
                session('user.type',$row[0]['type']);
                
            }else{
                $data['code']='1002';
                $data['message']='密码错误';
            }
        }else{
            $data['code']='1001';
            $data['message']='用户名不存在';
        }
        $data=json_encode($data);
        $this->ajaxReturn($data,'json');
    }
}